<?php
include_once "header.php";


$daftar_jenis = new Daftar_jenis();
$jenis = $daftar_jenis->getAll();
//var_dump($jenis);

$daftar_sifat = new Daftar_sifat_surat();
$sifat = $daftar_sifat->getAll();

$daftar_sm = new Daftar_surat_masuk();
$surat_masuk = $daftar_sm->getAll();

$daftar_user = new Daftar_user();
$user=$daftar_user->getAktifUser();
//var_dump($user);

$daftar_unit = new Daftar_unit();
$unit = $daftar_unit->getAll();
//var_dump($unit);
						 


$cek_field="";

if (ISSET($_POST["tambah_sk"])){

	if($_POST['jenis']=="" || $_POST['hal']=="" || $_POST['sifat']=="" || $_POST['konseptor']=="" || 
	$_POST['unit_konseptor']=="" || $_POST['unit_atasan_konseptor']=="" || $_POST['penandatangan']==""){
		
		$cek_field = "Peringatan: Silahkan isikan seluruh data yang tersedia.";
	
	} else {
		$daftar_sk = new Daftar_surat_keluar();
		$surat_keluar = new Surat_keluar();
		
		$surat_keluar->setHal($_POST['hal']);
		$surat_keluar->setSifat($_POST['sifat']);
		$surat_keluar->setLampiran($_POST['lampiran']);
		$surat_keluar->setTglKonsep(date("Y-m-d"));
		$surat_keluar->setJenis($_POST['jenis']);
		$surat_keluar->setReferensi($_POST['referensi']);
		$surat_keluar->setKonseptor($_POST['konseptor']);
		$surat_keluar->setUnitKonseptor($_POST['unit_konseptor']);
		$surat_keluar->setUnitAtasanKonseptor($_POST['unit_atasan_konseptor']);
		$surat_keluar->setPenandatangan($_POST['penandatangan']);
		var_dump($surat_keluar);
		
		$daftar_sk->add($surat_keluar);
		
		header("Location:surat_keluar.php");
		}
	
}
?>

<div id="container">
	<div id="errorcont">
		<?php echo $cek_field;
		?>
	</div>
	<div id="maincont">
		<?php include_once "menu_samping.php"; ?>
		<div id="mainright">
			<div id="title">
			Surat Keluar > Rekam
			</div>
			<div id="body">
			</br>
			<form name="form1" method="POST" action="rekam_sk.php">
			<input type="hidden" name="tambah_sk">
			<table  cellspacing=0 cellpadding=4 width=100%>		
				<tr>
					<td>Jenis</td>
					<td>:</td>
					<td>
					<select name="jenis">
					<option value="">Pilih jenis surat keluar</option>
					<?php
						foreach($jenis as $Jenis){
					?>
							<option value="<?php echo $Jenis->getId();?>"><?php echo ucwords($Jenis->getJenis());?></option>
					
						<?php }?>
					
					</select>
					</td>
				</tr>
				<tr>	
					<td>Sifat</td>
					<td>:</td>
					<td>
					<select name="sifat">
					<option value="">Pilih Sifat surat</option>
					<?php
						foreach($sifat as $Sifat){
					?>
							<option value="<?php echo $Sifat->getId();?>"><?php echo ucwords($Sifat->getSifat());?></option>
					
						<?php }?>
					
					</select>
					</td>
				</tr>
				<tr>	
					<td>Hal</td>
					<td>:</td>
					<td><input type="text" name="hal" id="hal" size=100></td>
				</tr>
				
				<tr>	
					<td>Lampiran</td>
					<td>:</td>
					<td><input type="text" name="lampiran" ></td>
				</tr>
				<tr>	
					<td>Referensi Surat</td>
					<td>:</td>
					<td>
					<select name="referensi">
					<option value="">Pilih Referensi surat</option>
					<?php
						foreach($surat_masuk as $sm){
					?>
							<option value="<?php echo $sm->getId();?>"><?php echo $sm->getNomor();?></option>
					
						<?php }?>
					
					</select>
					</td>
				</tr>
				
				<tr>	
					<td>Konseptor</td>
					<td>:</td>
					<td>
					<select name="konseptor">
	
					<?php
						foreach($user as $User){
							if($_SESSION['nip']== $User->getNip()){
								echo "<option value=".$User->getNip()." selected>".ucwords($User->getNama())." - NIP.".$User->getNip()."</option>";;
							} else{
								echo "<option value=".$User->getNip().">".ucwords($User->getNama())." - NIP.".$User->getNip()."</option>";
							}
						}
					?>
					</select>
					</td>
				</tr>
				
				<tr>	
					<td>Unit Konseptor</td>
					<td>:</td>
					<td>
					<select name="unit_konseptor">
					<option value="">Pilih Unit Konseptor</option>
					<?php
						foreach($unit as $Unit){
					?>
							<option value="<?php echo $Unit->getKd_unit();?>"><?php echo ucwords($Unit->getUnit());?></option>
					
						<?php }?>
					
					</select>
					</td>
				</tr>
				
				<tr>	
					<td>Unit Atasan Konseptor</td>
					<td>:</td>
					<td>
					<select name="unit_atasan_konseptor">
					<option value="">Pilih Unit Atasan Konseptor</option>
					<?php
						foreach($unit as $Unit){
					?>
							<option value="<?php echo $Unit->getKd_unit();?>"><?php echo ucwords($Unit->getUnit());?></option>
					
						<?php }?>
					
					</select>
					</td>
				</tr>
				
				<tr>	
					<td>Penandatangan</td>
					<td>:</td>
					<td>
					<select name="penandatangan">
	
					<?php
						foreach($user as $User){
							echo "<option value=".$User->getNip().">".ucwords($User->getNama())." - NIP.".$User->getNip()."</option>";
						}
					?>
					</select>
					</td>
				</tr>
			</table>
			<br>
			<input type="submit" value="Simpan"> 
			<input type="button" value="Batal" onClick="window.location.href='surat_keluar.php'">
			</form>
						
			</div>
        </div>
	</div>
</div>
<?php
	include_once "footer.php";
?>

<script type="text/javascript">
	$(function() { 
	$("#tgl").datepicker({dateFormat: "yy-mm-dd",
											buttonImage:'jquery/css/images/calendar.gif',
											buttonImageOnly: true,
											showOn: 'button'
	}); 
	});
</script>